package com.zjw.core.reflect;

import java.lang.reflect.Field;


/**
 * 获取成员属性(私有，公有)，修改属性的值
 * */
public class ReflectPrivatePropertyExample {

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Son son = new Son();
        Class sonClass = Son.class;

        Field field = sonClass.getDeclaredField("bookName");

        if(field != null){
            System.out.println(son.getBookName());
            field.setAccessible(true);
            field.set(son,"世界首富");
            System.out.println("我就是"+ son.getBookName());
        }
    }
}
